package cn.stu.flowable.controller;


import cn.stu.common.utils.R;
import cn.stu.flowable.domain.req.PageReq;
import cn.stu.flowable.service.ISysDeployFormService;
import cn.stu.flowable.service.ISysFormService;
import cn.stu.framework.entity.SysDeployForm;
import cn.stu.framework.entity.SysForm;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 流程表单Controller
 *
 * @author Tony
 * @date 2021-04-03
 */
@RestController
@RequestMapping("/flowable/form")
public class SysFormController {
    @Autowired
    private ISysFormService sysFormService;

    @Autowired
    private ISysDeployFormService sysDeployFormService;

    /**
     * 查询流程表单列表
     */
    @GetMapping("/list")
    public R<Page<SysForm>> list(PageReq pageReq, SysForm sysForm) {
        return sysFormService.selectSysFormList(pageReq, sysForm);
    }


    @GetMapping("/formList")
    public R<Page<SysForm>> formList(PageReq pageReq, SysForm sysForm) {
        return sysFormService.selectSysFormList(pageReq, sysForm);
    }


    /**
     * 获取流程表单详细信息
     */
    @GetMapping(value = "/{formId}")
    public R getInfo(@PathVariable("formId") Long formId) {
        return R.ok(sysFormService.selectSysFormById(formId));
    }

    /**
     * 新增流程表单
     */
    @PostMapping
    public R add(@RequestBody SysForm sysForm) {
        return R.ok(sysFormService.insertSysForm(sysForm));
    }

    /**
     * 修改流程表单
     */
    @PutMapping
    public R edit(@RequestBody SysForm sysForm) {
        return R.ok(sysFormService.updateSysForm(sysForm));
    }

    /**
     * 删除流程表单
     */
    @DeleteMapping("/{formIds}")
    public R remove(@PathVariable Long[] formIds) {
        return R.ok(sysFormService.deleteSysFormByIds(formIds));
    }


    /**
     * 挂载流程表单
     */
    @PostMapping("/addDeployForm")
    public R addDeployForm(@RequestBody SysDeployForm sysDeployForm) {
        return R.ok(sysDeployFormService.insertSysDeployForm(sysDeployForm));
    }
}
